/**
输入：head = [1,3,2]
输出：[2,3,1]

*/


/**
还有一个思路是：使用栈
*/


/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public int[] reversePrint(ListNode head) {
        ListNode temp=head;
        int count=0;
        while(temp!=null){
            count++;
            temp=temp.next;
        }
        int[]res=new int[count];
        temp=head;
        while(temp!=null){
            res[count-1]=temp.val;
            count--;
            temp=temp.next;
        }
        return res;
    }
}